import Vue from 'vue'
import VueRouter from 'vue-router'

// 引用路由
import Layout from '@/views/layout'
import Login from '@/views/login'
import Dashboard from '@/views/dashboard'
import Article from '@/views/article'
import PointManagement from '@/views/PointManagement'
import PointManagement2 from '@/views/pointManagement2'
import PointManagement3 from '@/views/pointManagement3'
import ReconciliationStatistics from '@/views/reconciliationStatistics'
import personnelManagement from '@/views/personnelManagement'
import Article1 from '@/views/article1'
import store from '@/store'
import fixingFm from '@/views/fixing/fixingFm'
import fixingState from '@/views/fixing/fixingState'
import fixingType from '@/views/fixing/fixingType'
import GoodsType from '@/views/goodstype'
import GoodsManage from '@/views/goodsmanage'
import Strategy from '@/views/strategy'
import Order from '@/views/order'
import usercount from '@/views/userCount/usercount'
import Renyuan from '@/views/renyuan'
Vue.use(VueRouter)
Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/login', component: Login },
    {
      path: '/',
      component: Layout,
      redirect: '/dashboard',
      children: [
        { path: 'renyuan', component: Renyuan },
        { path: 'dashboard', component: Dashboard },
        { path: 'article', component: Article },
        { path: 'article1', component: Article1 },
        { path: 'pointmanagement', component: PointManagement },
        { path: 'pointmanagement2', component: PointManagement2 },
        { path: 'pointmanagement3', component: PointManagement3 },
        {
          path: 'ReconciliationStatistics',
          component: ReconciliationStatistics
        },
        { path: 'personnelManagement', component: personnelManagement },
        { path: 'fixingFm', component: fixingFm },
        { path: 'fixingState', component: fixingState },
        { path: 'fixingType', component: fixingType },
        { path: 'goodstype', component: GoodsType },
        { path: 'goodsmanage', component: GoodsManage },
        { path: 'strategy', component: Strategy },
        { path: 'order', component: Order },
        { path: 'fixingFm', component: fixingFm },

        { path: 'usercount', component: usercount }
      ]
    }
  ]
})

const whiteList = ['/login']

router.beforeEach((to, from, next) => {
  const { token } = store.state.user
  console.log(token)
  if (token) {
    next()
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
export default router
